package com.fool
{
	public class User extends Player
	{
		public var isAttacking:Boolean = true;
		
		public function User(name:String)
		{
			super(name);
		}
		
		public function valid(selectedCard:Card, tableCards:Array):Boolean
		{
			var index:int = source.source.indexOf(selectedCard)
			if ( index == -1)
				return false
				
			var card:Card = source.source[index] as Card
			//deserialize and check is compare in other cards 
			
			var result:Boolean = false;
			//mark disabled cards
			if (isAttacking) 
			{
				if ( Util.isEmpty( (tableCards) ))//.empty?
				{
					return true
				}
				
				result = isEqualRank( tableCards, card )
					
			}else{
				var attackingCard:Card = tableCards[tableCards.length-1] as Card//.last
				result = attackingCard.compareIsStronger(card);
			}
			
			return result
		}
		
		public function getListOfDefendingCards(card:Card):Array
		{
			var result:Array;
			for each (var item:Card in source) 
			{
				item.enabled = card.compareIsStronger(item);
				if (item.enabled)
				{
					if (!result)
						result = [];
					
					result.push(item);
				}
			}
			return result;
		}
	}
}